import * as request from '../../utils/request';
import config from "../../config/config";

export function getHistoryRecords(params) {
    return request.get(`${config.api.memory.getHistoryRecords}`, params, false);
}

export function deleteHistoryRecord(params) {
    return request.post(`${config.api.memory.deleteHistoryRecord}`, params, false);
}

export function getMemoryDetails(params) {
    return request.get(`${config.api.memory.getMemoryDetails}`, params, false);
}

export function updateHistoryRecord(params) {
    return request.post(`${config.api.memory.updateHistoryRecord}`, params, false);
}

export function downloadMemoryDetails(params) {
    let fileName = params?.name + "-" + params?.create_time?.replaceAll("-", "")?.replaceAll(":", "")?.replaceAll(" ", "");
    return request.downlaod(`${config.api.memory.downloadMemoryDetails}`, params, "blob").then(res => {
        let event = document.createEvent("MouseEvents");
        let a = document.createElement("a");
        a.href = window.URL.createObjectURL(res);
        a.download = fileName;
        event.initEvent("click", true, true);
        a.dispatchEvent(event);
    });
}
